package com.fingard.avatar.website.model.bean;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fingard.avatar.website.model.enums.ResultCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
 * @author 徐一涛
 * @date 2022/4/26
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class PageView<T> extends BaseResultContext {
    private List<T> rows;
    private Long total;

    public static <T> PageView<T> success(List<T> data, Long total) {
        PageView<T> t = new PageView<>();
        t.setRows(data);
        t.setCode(ResultCode.SUCCESS.getValue());
        t.setSuccess(true);
        t.setTotal(total);
        return t;
    }

    public static <T> PageView<T> success(IPage<T> page) {
        PageView<T> t = new PageView<>();
        t.setRows(page.getRecords());
        t.setCode(ResultCode.SUCCESS.getValue());
        t.setSuccess(true);
        t.setTotal(page.getTotal());
        return t;
    }
}
